package _0219_._04_example.controller;

import _0219_._04_example.model.Product;
import _0219_._04_example.service.ProductService;
import _0219_._04_example.service.impl.ProductServiceImpl;

public class ProductController {

    // 创建一个对象
    ProductService productService = new ProductServiceImpl();

    // 1. 获取所有的商品对象
    public Product[] getAllProducts() {
        Product[] allProducts = productService.getAllProducts();
        return allProducts;
    }


    // 2. 插入一个商品到数组中
    public boolean insertProduct(int id, String productName, double price, String describe) {
        // 封装数据 ----> 对象
        Product product = new Product(id,productName,price,describe);

        // 调用service
        boolean ret = productService.insertProduct(product);
        return ret;
    }

    //3. 查询商品, 根据id/商品名查询商品详情, 并返回结果(商品对象)
    public Product searchForProducts(int id)
    {
        //封装数据 ----> 对象
        Product product = productService.searchForProducts(id);
        //调用service
        return product;
    }
    public Product searchForProducts(String productName)
    {
        //封装数据 ----> 对象
        Product product = productService.searchForProducts(productName);
        //调用service
        return product;
    }

    //4.更新商品
    public Product updateProducts(int id,String productName,double price,String describe)
    {
        //封装数据 ----> 对象
        Product product = new Product(id,productName,price,describe);
        return product;
    }

    public boolean removeProduct(int id)
    {
        //封装数据 ----> 对象
        boolean ret = productService.removeProduct(id);
        return ret;

    }
}
